 package com.freight.base.dao;

 import com.freight.base.entity.Area;
 import com.freight.base.vo.AreaListVo;
 import com.freight.base.vo.AreaVo;
 import com.freight.core.base.FreightBaseDao;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.Param;

 import java.util.List;

 /**
 * 区域维表数据处理层
 * @author huyingtai
 */
public interface AreaDao extends FreightBaseDao<Area, Long> {

  @Query(value = "select new com.freight.base.vo.AreaVo(area.areaCode,area.areaName,city.cityCode,city.cityName,province.provinceCode,province.provinceName)" +
          "from Area area " +
          "left join City city on  area.cityCode = city.cityCode " +
          "left join Province province on city.provinceCode = province.provinceCode " +
          "where area.areaCode =?1 ")
  AreaVo getAreaVoLevel(@Param("areaCode") String areaCode);

  @Query(value = "select new com.freight.base.vo.AreaVo(area.areaCode,area.areaName,city.cityCode,city.cityName,province.provinceCode,province.provinceName)" +
             "from Area area " +
             "left join City city on  area.cityCode = city.cityCode " +
             "left join Province province on city.provinceCode = province.provinceCode " +
             "where area.areaCode in (:areaCodes) ")
  List<AreaVo> getAreaVoLevel(@Param("areaCodes") List<String> areaCodes);

  @Query(value = "select new com.freight.base.vo.AreaListVo(area.areaCode,area.areaName,area.lng,area.lat)" +
         "from Area area where area.cityCode = :code ")
  List<AreaListVo> getByAreaList(@Param("code") String code);

}